package cn.lanqiao.book.dao.impl;

import cn.lanqiao.book.dao.IBaseDao;
import cn.lanqiao.book.dao.IAdminDao;
import cn.lanqiao.book.pojo.Admin;

import java.util.List;

public class AdminDaoImplI extends IBaseDao implements IAdminDao {
    @Override
    public void addAdmin(Admin admin) {
        String sql = "insert into b_user(u_username,u_password,u_email,u_sex,u_qq,u_type) values(?,?,?,?,?,?)";
        update(sql, admin.getU_username(), admin.getU_password(), admin.getU_email(), admin.getU_sex(), admin.getU_qq(), admin.getU_type());

    }

    @Override
    public List<Admin> queryAll() {
        String sql = "select * from b_user";
        return queryForList(Admin.class, sql);

    }

    @Override
    public void deleteAdmin(String name) {
        String sql = "delete from b_user where u_username = ?";
        update(sql, name);
    }

    @Override
    public Admin queryForOne(String name) {
        String sql = "select * from b_user where u_username = ?";
        return queryForOne(Admin.class, sql, name);
    }

    @Override
    public void updateAdmin(Admin admin) {
        String sql = "update b_user set u_username =? , u_password = ? , u_email = ? , u_sex = ? , u_qq= ?   where u_Id = ?";
        update(sql, admin.getU_username(), admin.getU_password(), admin.getU_email(), admin.getU_sex(), admin.getU_qq(), admin.getU_id());
    }

    @Override
    public List<Admin> search(String name) {
        String sql = "select * from b_user where u_username like ?";
        return queryForList(Admin.class, sql, name);
    }

    @Override
    public void changerPassword(int id, String password) {
        String sql = "update b_user set u_password = ? where u_Id = ?";
        update(sql, password, id);
    }

    @Override
    public Admin checkname(String name) {
            String sql = "select * from b_user  where u_username = ?";
            return queryForOne(Admin.class, sql, name);
    }
    @Override
    public Admin checkemail(String email) {
            String sql = "select * from b_user  where u_email = ?";
            return queryForOne(Admin.class, sql, email);
    }


}
